package edu.mercer.sse658.amazonbkp;

import java.nio.file.Path;
import java.nio.file.Paths;

import com.google.common.collect.ImmutableMap;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

public interface ConfigConstants 
{
	enum CREDENTIALS
	{
		/** Default file name, path for AWS id, secret key properties. */
		
		FILE ("credentials.aws");
		
		private String _fileName = "";
		
		CREDENTIALS( final String filename )
		{
			_fileName = filename;
			
		}//constructor
		
		
		public String asString(){ return _fileName; }

		public Path asPath(){ return Paths.get(_fileName); }

	}//enum

	
	enum JOBS
	{
		/** Default timeout for awaiting AWS job completion. */
		
		TIMEOUT (480L),
		
		/** 
		 * Default interval, frequency of checks/polling for job 
		 * completion.
		 */
		
		POLL (120L),
		
		ACTIVE_FILE_NAME ("current_aws_job");
		
		private Long _val = 0L;
		
		private String _valStr = "";
		
		JOBS( final Long val )
		{
			_val = val;
			
		}//constructor
		
		JOBS( final String val )
		{
			_valStr = val;
			
		}//constructor
		
		public Long asLong(){ return _val; }
		
		public String asString(){ return _valStr; }

	}//enum

	
	enum AWS_SETTINGS
	{
		REGION ("us-east-1"),
		TOPIC_ARN ("topicARN"),
		SUBSCRIPTION_ARN ("snsSubscriptionARN"),
		QUEUE_URL ("queURLStr"),
		QUEUE_ARN ("sqsQueueARN"),
		INVENTORY_JOB ("inventory-retrieval"),
		INVENTORY_JOB_DESC ("list archive contents"),
		ARCHIVE_ID_LAYOUT ("^ArchiveId,(?<ArchID>[0-9a-zA-Z\\+\\-_]{138})"),
		ARCHIVE_REGEX_GROUP ("ArchiveId");
		
		String _value = "";
		
		public final ImmutableMap<String,String> URL_PREFIXES =
				
				ImmutableMap.of("glacier","glacier",
								"topic", "sns",
								"queue", "sqs");
		
		public final String URL_DOMAIN = "amazonaws.com";
		
		AWS_SETTINGS( final String valueIn )
		{
			_value = valueIn;
			
		}//constructor
		
		public String asString(){ return _value; }
		
		
		public String endPoint( final String serviceIn, 
								final String... regionIn )
		{
			checkNotNull( serviceIn, "null detected service argumment" );
			
			checkArgument( URL_PREFIXES.containsKey(serviceIn), 
					"service argument value not found/invalid" );
			
			String regionSelected = _value;
			
			if( regionIn != null && regionIn.length > 0 ) 
				regionSelected = regionIn[0]; 
			
			return "https://" + URL_PREFIXES.get(serviceIn) + "." + 
								regionSelected + "." + 
								URL_DOMAIN;
			
		}//method
		
	}//enum
	
	
}//interface
